package com.etc.zmall.service.impl;

import java.util.List;

import com.etc.util.DBUtil;
import com.etc.util.PageData;
import com.etc.zmall.dao.ShopCartDao;
import com.etc.zmall.dao.impl.ShopCartDaoImpl;
import com.etc.zmall.entity.Shop;
import com.etc.zmall.entity.Shopc;
import com.etc.zmall.service.ShopCartService;


/**

* <p>Title: ShopCartServiceImpl</p>

* <p>Description: </p>

* @author knowno

* @date 2021年1月11日

*/
public class ShopCartServiceImpl implements ShopCartService {
	ShopCartDao sc = new ShopCartDaoImpl();

	@Override
	public PageData<Shopc> showShopCar(int userid, int page, int pageSize, String keywords) {
		if (page < 1) {
			page = 1;
		} else if (page > pageSize) {
			page = pageSize;
		}
		PageData<Shopc> pd = sc.selShopCar(userid, page, pageSize, keywords);
		if (pd == null)
			return null;
		return pd;
	}

	@Override
	public boolean delGoods(int userid, String goodsname) {
		boolean flag = sc.delShopCar(userid, goodsname);
		if (flag)
			return true;
		return false;
	}

	@Override
	public boolean addGoods(Shopc shopc) {
		boolean flag = sc.addShopCar(shopc);
		if (flag)
			return true;
		return false;
	}

	@Override
	public Shopc showShopName(Shopc shopc) {
		String sql = "select shopname from ftm_shop where shopid=?";
		List<Shop> list = (List<Shop>) DBUtil.exQuery(sql, Shop.class, shopc.getShopid());
		if (list.size() == 0) {
			return null;
		}
		Shopc shopc1 = new Shopc(shopc.getUserid(), shopc.getShopid(), shopc.getGoodsname(), shopc.getShopccount(),
				shopc.getTotal(), list.get(0).getShopname());
		System.out.println(shopc1.getShopname());
		return shopc1;
	}
}
